package Campus.help.user.service.impl;


import Campus.help.user.dao.UserInfoMapper;
import Campus.help.user.entity.UserInfo;
import Campus.help.user.vo.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserInfoMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        //按用户名查询
        UserInfo userInfo = userMapper.getbyUserName(s);
        if(userInfo==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        //返回正确的用户信息
        return new LoginUser(userInfo);
    }

}
